<?php
include_once 'conn.php';
$id = $_GET['id'] ?? '';
//numeric:判斷是否為數值
if(!is_numeric($id) || $id == ''){
    echo "<script>alert('參數錯誤')</script>";
    exit;
}
//將投票的數值重新賦值給car ID
$sql = "update carinfo set carNum = carNum + 1 where id = $id";

$result = mysqli_query($conn,$sql);

//判斷result是否成功
if($result){
    echo "<script>alert('投票成功');location.href = 'index.php';</script>";
}else{
    echo "<script>alert('投票失敗')</script>";
}